<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>异步请求工程</h1>
<div>
    <input type="button" value="异步Get请求" @click="f1()">
    <input type="button" value="异步Post请求" @click="f2()">
    <a href="/bmi.html">BMI测试</a>
    <hr>
    <a href="reg.html">注册</a>
    <a href="login.html">登录</a>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
    let v=new Vue({
        el:"body>div",
        data:{
            info:"测试成功"
        },
        methods:{
            f1(){
                //发出异步的get请求
                // axios.get("/helloAxios").then(function (response) {
                    //response对象代表相应，里面装着服务器相应的数据response.data
                //     alert(response.data);
                //
                //
                // })
                axios.get("/p1?name=to&age=18").then(function (response) {
                    alert(response.data);

                })
            },
            f2(){
                //发出异步的post请求
               // axios.post("/helloAxios").then(function (response) {
               //     alert(response.data);
               // })
                //发出异步请求时传参
                let p = {title:"老冰棍",price:"1.0",num:"1000"};
                axios.post("/p2",p).then(function (response) {
                    alert(response.data);
                })
            }


        }
    })
</script>
</body>
</html>